package com.dmy.controller;

import com.dmy.common.entity.ResultBean;
import com.dmy.common.utils.QiniuImageServerUtil;
import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;

/**
 * create by YCQ for 2020/1/9 15:11
 */
@RestController
@RequestMapping("/file")
public class FileUploadController {

    @SneakyThrows
    @PostMapping("/upload")
    public ResultBean uploadFile(@RequestParam("file") MultipartFile file){
        byte[] bytes = file.getBytes();
        String url = QiniuImageServerUtil.getInstance().uploadFileWithByteArray(bytes);
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("url",url);
        return ResultBean.success(hashMap);
    }

}
